package com.mengxiangnongfu.controller.system;

import com.mengxiangnongfu.aspectj.annotation.Log;
import com.mengxiangnongfu.dto.OperLogDto;
import com.mengxiangnongfu.service.OperLogService;
import com.mengxiangnongfu.vo.AjaxResult;
import com.mengxiangnongfu.vo.DataGridView;
import io.swagger.annotations.Api;
import lombok.extern.log4j.Log4j2;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 操作日志
 *
 * @author Yang
 * @version 1.0
 * @date 2020/10/3 14:58
 */
@Log4j2
@RestController
@RequestMapping("/system/operlog/")
@Api(value = "操作日志管理")
public class OperLogController {

    @Resource
    private OperLogService operLogService;

    /**
     * @Description: 分页查询操作日志
     * @Param: [operLogDto]
     * @return: com.mengxiangnongfu.vo.AjaxResult
     * @Author: Yang
     * @Date: 2020/10/3 - 15:01
     */
    @GetMapping(value = "loadAllOperLogByPage")
    public AjaxResult loadAllOperLogByPage(@Validated OperLogDto operLogDto) {
        DataGridView dataGridView = operLogService.loadOperLogByPage(operLogDto);
        return AjaxResult.success("查询成功", dataGridView.getDataList(), dataGridView.getTotalCount());
    }

    /**
     * @Description:删除操作日志
     * @Param: [ids]
     * @return: com.mengxiangnongfu.vo.AjaxResult
     * @Author: Yang
     * @Date: 2020/10/3 - 15:03
     */
    @DeleteMapping("removeOperLog/{ids}")
    public AjaxResult removeOperLogByIds(@PathVariable Long[] ids) {
        log.info("批量删除日志");
        return AjaxResult.toAjax(operLogService.removeOperLogByIds(ids));
    }

    /**
     * @Description:删除全部操作日志
     * @Param: []
     * @return: com.mengxiangnongfu.vo.AjaxResult
     * @Author: Yang
     * @Date: 2020/10/3 - 15:04
     */
    @DeleteMapping("clearOperLogs")
    public AjaxResult clearOperLogs() {
        return AjaxResult.toAjax(operLogService.clearAllOperLogs());
    }

}
